/**
 * @作者:黎谢之
 * @创建时间：2021/7/7
 * @修改时间：2021/7/10
 */
package com.example.senior_bug.Service;

import com.example.senior_bug.EntityClass.Category;
import com.example.senior_bug.ToolClass.Result;
import com.example.senior_bug.Repository.BrandRepository;
import com.example.senior_bug.Repository.CategoryRepository;
import com.example.senior_bug.enm.MsgId;
import com.example.senior_bug.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class BrandService {

    @Autowired
    private CategoryRepository categoryRepository;
    @Autowired
    private BrandRepository brandRepository;


    /*用户二级页面传入二级分类名字获取三级分类列表
     * 7.7创建
     * */
    public Result GetBrandsByCategory(String CategoryName) {
        //判断二级分类是否存在
        if (categoryRepository.existsByName(CategoryName)) {
            Category category = categoryRepository.findByName(CategoryName);
            return ResultUtils.success(brandRepository.findByCategoryId(category.getId()));
        } else {
            return ResultUtils.error(MsgId.CATEGORY_NOT_FOUND);
        }
    }
}
